Skip to content

virtio: add the vhost-vsock backend for virtio-vsock#4006

Open
will-j-wright wants to merge 2 commits into
microsoft:mainfrom
will-j-wright:vhost-vsock
Open

virtio: add the vhost-vsock backend for virtio-vsock#4006
will-j-wright wants to merge 2 commits into
microsoft:mainfrom
will-j-wright:vhost-vsock

Conversation

@will-j-wright

Copy link
Copy Markdown
Contributor

Add the vhost-vsock backend for virtio-vsock, implemented as VhostVsockDevice. This backend manifests as AF_VSOCK on both ends of the connection by delegating the virtqueues to the kernel with /dev/vhost-vsock, rather than the user-mode AF_UNIX/AF_VSOCK hybrid model used by VirtioVsockDevice. This exposes the guest in the host's AF_VSOCK namespace, allowing users on the host to connect(AF_VSOCK, CID, port) to reach services inside guest.

Also add a new petri test exercising this scenario.

Copilot AI review requested due to automatic review settings July 22, 2026 22:08
@will-j-wright
will-j-wright requested a review from a team as a code owner July 22, 2026 22:08
@github-actions github-actions Bot added the Guide label Jul 22, 2026
@github-actions

Copy link
Copy Markdown

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

@github-actions github-actions Bot added the unsafe Related to unsafe code label Jul 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Linux-only virtio-vsock backend that delegates the virtqueue data path to the kernel via /dev/vhost-vsock, making the guest reachable from the host’s AF_VSOCK namespace. This integrates the backend end-to-end (resource handle + resolver + CLI + docs) and extends Petri/CI to exercise it.

Changes:

  • Introduce VhostVsockDevice (Linux vhost_vsock) implementation in virtio_vsock.
  • Wire the backend through virtio_resources, resolver registration, and a new openvmm CLI flag --virtio-vsock-vhost-cid.
  • Update Petri to connect to pipette over host AF_VSOCK, add a new Petri boot test, and prepare /dev/vhost-vsock in the nextest/flowey job.

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vmm_tests/vmm_tests/tests/tests/multiarch.rs Adds a Linux boot test that uses the vhost-vsock backend and validates host-to-guest AF_VSOCK connectivity via pipette.
vm/devices/virtio/virtio_vsock/src/vhost.rs New Linux vhost-vsock virtio-vsock device implementation + unit tests for CID validation, queue state encoding, and memory mapping.
vm/devices/virtio/virtio_vsock/src/resolver.rs Adds a Linux-only static resolver for the new vhost-vsock handle.
vm/devices/virtio/virtio_vsock/src/lib.rs Plumbs in the Linux-only vhost module and updates the crate-level unsafe rationale comment.
vm/devices/virtio/virtio_vsock/Cargo.toml Adds Linux-only dependencies needed by the vhost backend (nix ioctl, pal_event, sparse_mmap).
vm/devices/virtio/virtio_resources/src/lib.rs Adds VirtioVsockVhostHandle MeshPayload resource ID for selecting the vhost backend.
petri/src/vm/openvmm/runtime.rs Adds AF_VSOCK-based pipette connection path when a vhost-vsock CID is configured.
petri/src/vm/openvmm/construct.rs Chooses between user-mode vsock vs vhost-vsock resources and enforces shared-memory requirements when vhost-vsock is enabled.
petri/src/vm/mod.rs Extends PetriVmBuilder/properties with a Linux-only vhost-vsock guest CID knob (with_vhost_vsock).
petri/Cargo.toml Adds Linux-only vmsocket dependency for AF_VSOCK connections.
openvmm/openvmm_resources/src/lib.rs Registers the new Linux-only virtio-vsock vhost resolver.
openvmm/openvmm_entry/src/lib.rs Adds device creation from the new CLI option (--virtio-vsock-vhost-cid).
openvmm/openvmm_entry/src/cli_args.rs Defines CLI flag, CID parser/validation, and tests for the new option.
Guide/src/reference/openvmm/management/cli.md Documents --virtio-vsock-path and new --virtio-vsock-vhost-cid behavior/requirements.
flowey/flowey_lib_hvlite/src/test_nextest_vmm_tests_archive.rs Adds an optional pre-test step to modprobe vhost_vsock and chmod /dev/vhost-vsock.
flowey/flowey_lib_hvlite/src/_jobs/local_build_and_run_nextest_vmm_tests.rs Threads through the new prepare_vhost_vsock option (disabled for this local job).
flowey/flowey_lib_hvlite/src/_jobs/consume_and_test_nextest_vmm_tests_archive.rs Enables vhost-vsock preparation for Linux x86_64 nextest runs (where the new test applies).
Cargo.lock Records new dependency usage (notably nix and sparse_mmap).

Comment thread Guide/src/reference/openvmm/management/cli.md Outdated
Comment thread vm/devices/virtio/virtio_vsock/src/vhost.rs Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 22:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 1 comment.

Comment thread vm/devices/virtio/virtio_vsock/src/vhost.rs
Copilot AI review requested due to automatic review settings July 22, 2026 22:29

@chris-oo chris-oo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didn't look too much at vhost.rs, i need a bit more context to really review it / john perhaps has the right context

Comment thread flowey/flowey_lib_hvlite/src/test_nextest_vmm_tests_archive.rs Outdated
// that requires shared, file-backed memory.
let private_incompatible = firmware.is_openhcl() || firmware.is_pcat();
let private_incompatible =
firmware.is_openhcl() || firmware.is_pcat() || vhost_vsock_guest_cid.is_some();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a comment why this is private incompatible (because the kernel needs access, or why?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the bail below not have enough detail?

Comment thread petri/src/vm/openvmm/construct.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

vm/devices/virtio/virtio_vsock/src/vhost.rs:17

  • size_of is used unqualified in this module (e.g. when building the vhost memory table and device register length), but it isn’t imported into scope anywhere in the file. This will fail to compile unless each call is qualified (e.g. std::mem::size_of). Add a use core::mem::size_of; (or std::mem::size_of) near the other imports.
use crate::spec::VsockConfig;
use anyhow::Context as _;
use guestmem::GuestMemory;
use inspect::InspectMut;
use pal_event::Event;

Copilot AI review requested due to automatic review settings July 22, 2026 22:42
@will-j-wright
will-j-wright requested a review from a team as a code owner July 22, 2026 22:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

vm/devices/virtio/virtio_vsock/src/vhost.rs:22

  • size_of::<...>() is used in this module (e.g. when building the vhost memory table), but size_of isn't imported, so this file won't compile on Linux. Import size_of from std::mem (or core::mem).
use pal_event::Event;
use sparse_mmap::SparseMapping;
use std::os::fd::AsFd as _;
use std::os::fd::AsRawFd as _;
use std::os::fd::OwnedFd;
use std::os::fd::RawFd;

@github-actions

Copy link
Copy Markdown

Comment thread vm/devices/virtio/virtio_vsock/src/vhost.rs
Comment thread vm/devices/virtio/virtio_vsock/src/vhost.rs
Comment thread vm/devices/virtio/virtio_resources/src/lib.rs
Copilot AI review requested due to automatic review settings July 24, 2026 17:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

vm/devices/virtio/virtio_vsock/src/vhost.rs:17

  • This module calls size_of::<...>() (e.g. when building the vhost memory table), but size_of isn’t imported, so the file won’t compile as-is. Add an explicit use std::mem::size_of; near the other imports.
use crate::spec::VsockConfig;
use anyhow::Context as _;
use guestmem::GuestMemory;
use inspect::InspectMut;
use pal_event::Event;

Comment on lines +675 to +685
match self.memory().read_used_index(&runtime.params) {
Ok(index) => index,
Err(error) => {
tracelimit::warn_ratelimited!(
error = &*error as &dyn std::error::Error,
index,
"failed to read vhost-vsock used index"
);
return None;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Guide unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants